package com.github.baichuan.application.scaffold.controller;

import com.github.baichuan.application.scaffold.security.AuthenticationService;
import com.github.baichuan.application.scaffold.dto.authentication.DingCredential;
import com.github.baichuan.application.scaffold.dto.authentication.PasswordCredential;
import com.github.baichuan.web.dto.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Tag(name = "认证服务")
@RestController
@RequestMapping("/auth")
public class AuthenticationController {
    @Autowired
    private AuthenticationService authService;

    @PostMapping("/password")
    @Operation(summary = "用户名密码认证")
    public ResponseEntity<Result> password(@RequestHeader("x-application-code") @Parameter(hidden = true) String application,
                                   @RequestBody @Valid PasswordCredential credential) {
        Result result = authService.auth(application, credential);
        return ResponseEntity.ok(result);
    }

    @PostMapping("/ding")
    @Operation(summary = "钉钉用户认证")
    public ResponseEntity<Result> ding(@RequestHeader("x-application-code") @Parameter(hidden = true) String application,
                               @RequestBody @Valid DingCredential credential){
        Result result = authService.auth(application, credential);
        return ResponseEntity.ok(result);
    }
}
